import java.util.*;
public class Day20 {
    public int lenLongestFibSubseq(int[] arr) {
        int n = arr.length;
        int[][] dp = new int[n][n];
        Map<Integer,Integer> map = new HashMap<>();
        int ret = 2;
        for(int i=0;i<n;i++) {
            map.put(arr[i],i);
            for(int j=i+1;j<n;j++) {
                dp[i][j]=2;
                int tmp = arr[j] - arr[i];
                int k = map.getOrDefault(tmp,-1);
                if(k!=-1) {
                    if(k<i) {
                        dp[i][j] = dp[k][i] + 1;
                    }
                }
                ret = Math.max(ret,dp[i][j]);
            }
        }
        return ret==2?0:ret;
    }
}
